﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;

namespace GUI
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private Form KiemTraTonTai(Type formType)
        {
            foreach (Form f in this.MdiChildren)
            {
                if (f.GetType() == formType)
                    return f;
            }
            return null;
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            Login loginfrm = new Login();
            loginfrm.ShowDialog();
            if (ThongTin.NhanVienTT == null)
                Application.Exit();
        }

        private void tạoĐơnHàngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form frm = KiemTraTonTai(typeof(DonHang));
            if (frm != null)
                frm.Activate();
            else
            {
                DonHang frmDonHang = new DonHang();
                frmDonHang.MdiParent = this;
                frmDonHang.Show();
            }
        }

        private void quảnLýĐơnHàngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form frm = KiemTraTonTai(typeof(QuanLyDonHang));
            if (frm != null)
                frm.Activate(); // Form đã tồn tại, kích hoạt
            else
            {
                QuanLyDonHang frmQuanLyDonHang = new QuanLyDonHang();
                frmQuanLyDonHang.MdiParent = this;
                frmQuanLyDonHang.Show();
            }
        }

        private void quảnLýKhuyếnMạiToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form frm = KiemTraTonTai(typeof(QuanLyKhuyenMai));
            if (frm != null)
                frm.Activate(); // Form đã tồn tại, kích hoạt
            else
            {
                QuanLyKhuyenMai frmQuanLyKhuyenMai = new QuanLyKhuyenMai();
                frmQuanLyKhuyenMai.MdiParent = this;
                frmQuanLyKhuyenMai.Show();
            }
        }

        private void quảnLýMónToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form frm = KiemTraTonTai(typeof(QuanLyMonAn));
            if (frm != null)
                frm.Activate(); // Form đã tồn tại, kích hoạt
            else
            {
                QuanLyMonAn frmQuanLyMonAn = new QuanLyMonAn();
                frmQuanLyMonAn.MdiParent = this;
                frmQuanLyMonAn.Show();
            }
        }

        private void thêmMónToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form frm = KiemTraTonTai(typeof(MonAn));
            if (frm != null)
                frm.Activate(); // Form đã tồn tại, kích hoạt
            else
            {
                MonAn frmMonAn = new MonAn();
                frmMonAn.MdiParent = this;
                frmMonAn.Show();
            }
        }

        private void xemToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form frm = KiemTraTonTai(typeof(KhuyenMai));
            if (frm != null)
                frm.Activate(); // Form đã tồn tại, kích hoạt
            else
            {
                KhuyenMai frmKhuyenMai = new KhuyenMai();
                frmKhuyenMai.MdiParent = this;
                frmKhuyenMai.Show();
            }
        }

        private void tạoĐơnHàngToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            Form frm = KiemTraTonTai(typeof(DonHang));
        }
    }
}
